package org.open.oasis.docs.wsbpel._2._0.process.abstract_.util;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.AbstractPackage;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TActivity;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TAssign;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TCompensate;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TCompensateScope;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TEmpty;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TExit;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TFlow;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TForEach;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TIf;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TInvoke;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TOpaqueActivity;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TPick;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TReceive;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TRepeatUntil;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TReply;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TRethrow;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TScope;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TSequence;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TThrow;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TValidate;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TWait;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TWhile;

public class ActivitySetter {

	private static RootFinder rootFinder = new RootFinder();
	private static NameFinder nameFinder = new NameFinder();
	
	public static void set(EObject container, TActivity a) {
		EStructuralFeature feature=container.eClass().getEStructuralFeature(nameFinder.doSwitch(a));
		container.eSet(feature, a);
	}

	public static void add(FeatureMap fmap, TActivity a) {
		EStructuralFeature ef = rootFinder.doSwitch(a);
		if (ef != null) {
			fmap.add(ef, a);
		}
	}

	private static class NameFinder extends AbstractSwitch<String> {
		@Override
		public String caseTAssign(TAssign object) {
			return "assign";
		}

		@Override
		public String caseTCompensate(TCompensate object) {
			return "compensate";
		}

		@Override
		public String caseTCompensateScope(TCompensateScope object) {
			return "compensateScope";
		}

		@Override
		public String caseTEmpty(TEmpty object) {
			return "empty";
		}

		@Override
		public String caseTExit(TExit object) {
			return "exit";
		}

		@Override
		public String caseTFlow(TFlow object) {
			return "flow";
		}

		@Override
		public String caseTForEach(TForEach object) {
			return "forEach";
		}

		@Override
		public String caseTIf(TIf object) {
			return "if";
		}

		@Override
		public String caseTInvoke(TInvoke object) {
			return "invoke";
		}

		@Override
		public String caseTOpaqueActivity(TOpaqueActivity object) {
			return "opaqueAcitivity";
		}

		@Override
		public String caseTPick(TPick object) {
			return "pick";
		}

		@Override
		public String caseTReceive(TReceive object) {
			return "receive";
		}

		@Override
		public String caseTRepeatUntil(TRepeatUntil object) {
			return "repeatUntil";
		}

		@Override
		public String caseTReply(TReply object) {
			return "reply";
		}

		@Override
		public String caseTRethrow(TRethrow object) {
			return "rethrow";
		}

		@Override
		public String caseTScope(TScope object) {
			return "scope";
		}

		@Override
		public String caseTSequence(TSequence object) {
			return "sequence";
		}

		@Override
		public String caseTThrow(TThrow object) {
			return "throw";
		}

		@Override
		public String caseTValidate(TValidate object) {
			return "validate";
		}

		@Override
		public String caseTWait(TWait object) {
			return "wait";
		}

		@Override
		public String caseTWhile(TWhile object) {
			return "while";
		}
	}
	
	private static class RootFinder extends AbstractSwitch<EStructuralFeature> {
		@Override
		public EStructuralFeature caseTAssign(TAssign object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Assign();
		}

		@Override
		public EStructuralFeature caseTCompensate(TCompensate object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Compensate();
		}

		@Override
		public EStructuralFeature caseTCompensateScope(TCompensateScope object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_CompensateScope();
		}

		@Override
		public EStructuralFeature caseTEmpty(TEmpty object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Empty();
		}

		@Override
		public EStructuralFeature caseTExit(TExit object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Exit();
		}

		@Override
		public EStructuralFeature caseTFlow(TFlow object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Flow();
		}

		@Override
		public EStructuralFeature caseTForEach(TForEach object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_ForEach();
		}

		@Override
		public EStructuralFeature caseTIf(TIf object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_If();
		}

		@Override
		public EStructuralFeature caseTInvoke(TInvoke object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Invoke();
		}

		@Override
		public EStructuralFeature caseTOpaqueActivity(TOpaqueActivity object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_OpaqueActivity();
		}

		@Override
		public EStructuralFeature caseTPick(TPick object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Pick();
		}

		@Override
		public EStructuralFeature caseTReceive(TReceive object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Receive();
		}

		@Override
		public EStructuralFeature caseTRepeatUntil(TRepeatUntil object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_RepeatUntil();
		}

		@Override
		public EStructuralFeature caseTReply(TReply object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Reply();
		}

		@Override
		public EStructuralFeature caseTRethrow(TRethrow object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Rethrow();
		}

		@Override
		public EStructuralFeature caseTScope(TScope object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Scope();
		}

		@Override
		public EStructuralFeature caseTSequence(TSequence object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Sequence();
		}

		@Override
		public EStructuralFeature caseTThrow(TThrow object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Throw();
		}

		@Override
		public EStructuralFeature caseTValidate(TValidate object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Validate();
		}

		@Override
		public EStructuralFeature caseTWait(TWait object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_Wait();
		}

		@Override
		public EStructuralFeature caseTWhile(TWhile object) {
			return AbstractPackage.eINSTANCE.getDocumentRoot_While();
		}
	}
}
